﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="dictionary.aspx.cs" Inherits="SampleSite.admin.dictionary" %>

<script src="/scripts/DialogHelper.js"></script>
<style type="text/css">
    .tb_grid { text-align:left;border:0px solid #0094ff;border-collapse: collapse; width:100%; }
    .tb_grid td{ border-bottom:1px solid #95B8E7; }
    .tb_grid tr{ height:30px; }
    .td_lbl{ width:10%; background:#6caef5; text-align:center;}
    .td_cnt{ width:35%; text-align:left; background:#E0ECFF;}
    .textarea { width:95% }
</style>

<div>
<table id="table" class="easyui-datagrid" title="" 
		data-options="idField:'Id', singleSelect:true,collapsible:true,url:'/dyajax/ur_dictionary/query',toolbar:toolbar">
	<thead>
		<tr>
			<th data-options="field:'Id',width:80, hidden:true">ID</th>
                <th data-options="field:'keyname', width:100">名称</th>                   
                <th data-options="field:'keygroup', width:100">分组</th>                                   
<%--                <th data-options="field:'state', width:100">状态</th>                   --%>
                <th data-options="field:'remark', width:100">备注</th>            
		</tr>
	</thead>
</table>
</div>

<div id="dlgAdd"
        class="easyui-dialog"
        style="width:800px;height:600px;padding:0px;"
        data-options="closed:true,resizable:true,modal:true,buttons:'#dlg-buttons',align:'center'">
        
    <form action="/dyajax/ur_dictionary/add" method="post">
        <table id="tblAdd" class="tb_grid" >
            <tr style="height:20px;"><td colspan="4">&nbsp;</td></tr>
                
            <tr>
                <td class="td_lbl">名称:</td>
                <td class="td_cnt"><input class="easyui-validatebox" id="_Add_keyname" name="keyname" data-options="required:true" /></td>
                
                <td class="td_lbl">分组:</td>
                <td class="td_cnt"><input class="easyui-validatebox" id="_Add_keygroup" name="keygroup" data-options="required:true" /></td>
                
            </tr>
                
            <tr>               
                <td class="td_lbl">备注:</td>
                <td class="td_cnt" colspan="3"><textarea class="easyui-validatebox textarea" id="_Add_remark" name="remark" data-options="required:true"></textarea></td>
            </tr>
                
            <tr>
                <td colspan="4" style="text-align:center; padding-top:10px">
                    <a href="javascript:void(0)" 
                        class="easyui-linkbutton do" 
                        id="btnAdd" 
                        iconcls="icon-ok" >确定</a>
                    <a href="javascript:void(0)" 
                        class="easyui-linkbutton close_dlg"
                        dlg="btnAdd"
                        iconcls="icon-cancel">关闭</a>
                </td>
            </tr>
        </table>
    </form>
</div>

<div id="dlgUpdate"
        class="easyui-dialog"
        style="width:800px;height:600px;padding:0px;"
        data-options="closed:true,resizable:true,modal:true,buttons:'#dlg-buttons',align:'center'">
        
    <form method="post">
        <table id="tblUpdate" class="tb_grid" >
            <tr style="height:20px;"><td colspan="4">&nbsp;</td></tr>                
            <tr>
                <td class="td_lbl">名称:</td>
                <td class="td_cnt"><input class="easyui-validatebox" id="_Update_keyname" name="keyname" data-options="required:true" /></td>
                
                <td class="td_lbl">分组:</td>
                <td class="td_cnt"><input class="easyui-validatebox" id="_Update_keygroup" name="keygroup" data-options="required:true" /></td>
            </tr>
            <tr>
                <td class="td_lbl">备注:</td>
                <td class="td_cnt" colspan="3"><textarea class="easyui-validatebox textarea" id="_Update_remark" name="remark" data-options="required:true"></textarea></td>
            </tr>
            <tr>
                <td colspan="4" style="text-align:center; padding-top:10px">
                    <a href="javascript:void(0)" 
                        class="easyui-linkbutton do" 
                        id="btnUpdate" 
                        iconcls="icon-ok" >确定</a>
                    <a href="javascript:void(0)" 
                        class="easyui-linkbutton close_dlg"
                        dlg="dlgUpdate"
                        iconcls="icon-cancel">关闭</a>
                </td>
            </tr>
        </table>
        <input type="hidden" id="_Update_Id" name="Id" />
    </form>
</div>

<script type="text/ecmascript">
    var dlgAdd = new _dialog('#dlgAdd', '添加');
    dlgAdd.beforeDo = function () {
        var form = dlgAdd.dlg.find('form');
        if (!form.form('validate'))
            return false;

        var data = form.serialize();
        $.post('/dyajax/ur_dictionary/add',
                data,
                function (res) {
                    if (res.state == 'ok') {
                        $.messager.alert('提示', '添加成功');
                        dlgAdd.close();
                        $('#table').datagrid('reload');
                    } else {
                        $.messager.alert('提示', '添加失败');
                    }
                }, 'json');
    }

    var dlgUpdate = new _dialog('#dlgUpdate', '修改');
    dlgUpdate.beforeShow = function () {
        var selected = $('#table').datagrid('getSelected');
        if (selected) {
            $('#dlgUpdate input').val('');
            $('#dlgUpdate select').val('');
            $('#dlgUpdate textarea').val('');

            $('#_Update_Id').val(selected.Id);

            $('#_Update_keyname').val(selected.keyname);
            $('#_Update_keygroup').val(selected.keygroup);
            $('#_Update_remark').val(selected.remark);

            return true;
        }
        else {
            $.messager.alert('提示', '请选择需要修改的行');
            return false;
        }
    }

    dlgUpdate.beforeDo = function () {
        var form = dlgUpdate.dlg.find('form');
        if (!form.form('validate'))
            return false;

        var data = form.serialize();
        $.post('/dyajax/ur_dictionary/update',
                data,
                function (res) {
                    if (res.state == 'ok') {
                        $.messager.alert('提示', '修改成功');
                        dlgUpdate.close();
                        $('#table').datagrid('reload');
                    } else {
                        $.messager.alert('提示', '修改失败');
                    }
                }, 'json');
    }

</script>
<script type="text/javascript">
    var toolbar = [{
        text: '添加',
        iconCls: 'icon-add',
        handler: function () {
            dlgAdd.show();
        }
    }, '-', {
        text: '修改',
        iconCls: 'icon-edit',
        handler: function () {
            dlgUpdate.show();
        }
    }, '-', {
        text: '删除',
        iconCls: 'icon-cancel',
        handler: function () {
            var selected = $('#table').datagrid('getSelected');
            if (selected) {
                $.messager.confirm('提示', '是否需要删除当前选择项?', function (r) {
                    if (r) {
                        $.post(
                            '/dyajax/ur_dictionary/delete',
                            { Id: selected.Id },
                            function (res) {
                                if (res.state == 'ok') {
                                    $.messager.alert('提示', '删除成功');
                                    $('#table').datagrid('reload');
                                }
                                else {
                                    $.messager.alert('提示', '删除失败');
                                }
                            }, 'json');
                    }
                });
            }
            else {
                $.messager.alert('提示', '请选择需要删除的行');
            }
        }
    }];
</script>
